// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Keyword.cs" company="Arizona State University">
//   Copyright (C) 2011-2012 Sukru Tikves and Arizona State University
//   
//   Released under Microsoft Public License (Ms-PL)
//   See http://cipsdata.codeplex.com/license for up to date license 
//   informaiton.
// </copyright>
// <summary>
//   Defines the Keyword type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Cips.DataMining
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics.CodeAnalysis;

    using Cips.DataMining.Properties;

    /// <summary>
    /// The keyword.
    /// </summary>
    public class Keyword
    {
        /// <summary>
        /// The Indonesian stop words.
        /// </summary>
        static readonly KeywordSet<string> StopWordsI = new KeywordSet<string>(Resources.IndonesianStopwords.Split(new char[0], StringSplitOptions.RemoveEmptyEntries));

        /// <summary>
        /// The English stop words.
        /// </summary>
        static readonly KeywordSet<string> StopWordsE = new KeywordSet<string>(Resources.EnglishStopwords.Split(new char[0], StringSplitOptions.RemoveEmptyEntries));

        /// <summary>
        /// Initializes a new instance of the <see cref="Keyword"/> class.
        /// </summary>
        /// <param name="text">
        /// The original text.
        /// </param>
        /// <param name="englishText">
        /// The english text.
        /// </param>
        public Keyword(IEnumerable<string> text, string englishText)
        {
            EnglishText = englishText;

            Text = new List<string>(text);
        }

        /// <summary>
        /// Gets the indonesian stop words.
        /// </summary>
        public static KeywordSet<string> IndonesianStopWords
        {
            get { return StopWordsI; }
        }

        /// <summary>
        /// Gets the english stop words.
        /// </summary>
        public static KeywordSet<string> EnglishStopWords
        {
            get { return StopWordsE; }
        }

        /// <summary>
        /// Gets the text.
        /// </summary>
        public IList<string> Text { get; private set; }

        /// <summary>
        /// Gets the english text.
        /// </summary>
        public string EnglishText { get; private set; }
    }

#if SILVERLIGHT
    // TODO implement IEnumerable<T>
    public class KeywordSet<T>
    {
        readonly Dictionary<T, bool> items = new Dictionary<T,bool>();

        public KeywordSet(IEnumerable<T> items)
        {
            foreach (var item in items)
                this.items[item] = true;
        }

        public bool Contains(T item)
        {
            return items.ContainsKey(item);
        }
    }
#else
    /// <summary>
    /// The keyword set. This class wraps the <see cref="HashSet{T}"/>.
    /// </summary>
    /// <typeparam name="T">
    /// Item type.
    /// </typeparam>
    [SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:FileMayOnlyContainASingleClass", Justification = "Reviewed. Suppression is OK here.")]
    public class KeywordSet<T> : HashSet<T>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="KeywordSet{T}"/> class.
        /// </summary>
        /// <param name="keywords">
        /// The keywords.
        /// </param>
        public KeywordSet(IEnumerable<T> keywords)
            : base(keywords)
        {
        }
    }
#endif
}